package com.icity.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.icity.entity.ChannelActive;
import com.icity.entity.ChannelAddUser;
import com.icity.entity.ChannelStart;
import com.icity.entity.DurationInfos;
import com.icity.entity.Partnerstatistical;
import com.icity.entity.TrendsUser;
import com.icity.entity.UserDistribution;
import com.icity.entity.UserTrends;

@Mapper
public interface TrendsUserMapper {

	@Select("select FROM_UNIXTIME('dateof','%Y-%m-%d ') as dateof,adduser,addregisteredaccount,startnum,activeuserday,activeuserweek,activeusermonth,usingthelength from tbl_statistics_trends_user ")
	List<TrendsUser> selectAllTrends(Map<Object, Object> map);

	@Select("<script>" + "select * " + "from tbl_statistics_trends_user where 1 = 1"
	 + " ORDER BY dateof desc"
			+ " limit #{page},#{limit} " + " </script>")
	List<TrendsUser> getLsit(Map<Object, Object> map);

	@Select("<script>" + "select count(id) from tbl_statistics_trends_user where 1 = 1" + " </script>")
	int selectCount(Map<Object, Object> map);

	@Select("select * from tbl_statistics_channel_active where now_date between #{startDate} and "
			+ "#{endDate}  order by now_date")
	List<ChannelActive> getdatanum(Map<Object, Object> params);

	@Select("select * from tbl_statistics_channel_adduser where now_date between #{startDate} and "
			+ "#{endDate}  order by now_date")
	List<ChannelAddUser> getaddusernum(Map<Object, Object> params);

	@Select("select * from tbl_statistics_channel_start where now_date between #{startDate} and "
			+ "#{endDate}  order by now_date")
	List<ChannelStart> getstartnum(Map<Object, Object> params);

	@Select("select count(id) from tbl_app_user where sex=1 and is_author_or_user = 1")
	List<Integer> selectappuserman();

	@Select("select count(id) from tbl_app_user where sex=2 and is_author_or_user = 1")
	List<Integer> selectappuserwoman();

	@Select("select count(id) from tbl_app_user where sex=0")
	List<Integer> selectappuserunknown();

	@Select("<script>" + "select province from tbl_icity_user_distribution where 1 = 1 "
			+ "<if test='application_unique_code != null'>"
			+ " and application_unique_code =#{application_unique_code} " + "</if>"

			+ "<if test='partner_id != null'>" + " and partner_id = #{partner_id}" + "</if>"
			+ "<if test='type != null'>" + " and type = #{type}" + "</if>" + " </script>")
	List<String> getUserDistribution(Map<Object, Object> map);

	@Select("<script>" + "select location_num from tbl_icity_user_distribution where 1 = 1 "
			+ "<if test='application_unique_code != null'>"
			+ " and application_unique_code =#{application_unique_code} " + "</if>"

			+ "<if test='partner_id != null'>" + " and partner_id = #{partner_id}" + "</if>"
			+ "<if test='type != null'>" + " and type = #{type}" + "</if>" + " </script>")
	List<Integer> getUserProvinceNumDistribution(Map<Object, Object> map);

	@Select("<script>" + "select location_num,province from tbl_icity_user_distribution where 1 = 1 "
			+ "<if test='application_unique_code != null'>"
			+ " and application_unique_code =#{application_unique_code} " + "</if>" + "<if test='type != null'>"
			+ " and type =#{type} " + "</if>" + "<if test='partner_id != null'>" + " and partner_id = #{partner_id}"
			+ "</if>" + " </script>")
	List<UserDistribution> getUserChinaDistribution(Map<Object, Object> map);

	@Select("<script>" + "select city from tbl_icity_user_distribution where 1 = 1 "
			+ "<if test='application_unique_code != null'>"
			+ " and application_unique_code =#{application_unique_code} " + "</if>"

			+ "<if test='partner_id != null'>" + " and partner_id = #{partner_id}" + "</if>"
			+ "<if test='type != null'>" + " and type =#{type} " + "</if>" + " </script>")
	List<String> getUsercityDistribution(Map<Object, Object> map);

	@Select("<script>" + "select location_num from tbl_icity_user_distribution where 1 = 1 "
			+ "<if test='application_unique_code != null'>"
			+ " and application_unique_code =#{application_unique_code} " + "</if>"

			+ "<if test='partner_id != null'>" + " and partner_id = #{partner_id}" + "</if>"
			+ "<if test='type != null'>" + " and type =#{type} " + "</if>" + " </script>")
	List<Integer> getUserNumDistributioncity(Map<Object, Object> map);

	@Select("<script>" + "select * " + "from tbl_statistics_partnermsg where 1 = 1" + "<if test='name != null'>"
			+ " and name like CONCAT('%','${name}','%') " + "</if>"

			+ " limit #{page},#{limit} " + " </script>")
	List<Partnerstatistical> getPartnertable(Map<Object, Object> map);

	@Select("<script>" + "select count(id) from tbl_statistics_partnermsg where 1 = 1" + " </script>")
	int selectpartnerCount(Map<Object, Object> map);

	@Select("select * from tbl_statistics_user_trend where date = #{date}")
	UserTrends getUserTrend(@Param("date") String date);

	@Select("select * from tbl_statistics_trends_user where dateof between #{startDate} and "
    		+ "#{endDate}  order by dateof")
	List<TrendsUser> getTrendsUserByType(Map<Object,Object> map);

	@Select("select * from tbl_statistics_durationinfos where date between #{startDate} and "
    		+ "#{endDate}  order by date")
	List<DurationInfos> getDurationInfos(Map<Object,Object> map);
}
